package com.ruoyi.web.controller.baseInfo;

import com.ruoyi.baseInfo.domain.Customer;
import com.ruoyi.baseInfo.service.ICustomerService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 顾客信息 操作处理
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/customer")
public class CustomerController extends BaseController
{
    @Autowired
    private ICustomerService customerService;

    /**
     * 获取顾客信息列表
     */
    @PreAuthorize("@ss.hasPermi('baseInfo:customer:list')")
    @GetMapping("/list")
    public TableDataInfo list(Customer customer)
    {
        startPage();
        List<Customer> list = customerService.selectCustomerList(customer);
        return getDataTable(list);
    }

    /**
     * 根据顾客ID获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('baseInfo:customer:query')")
    @GetMapping(value = "/{customerId}")
    public AjaxResult getInfo(@PathVariable Long customerId)
    {
        return success(customerService.selectCustomerById(customerId));
    }

    /**
     * 新增顾客信息
     */
    @PreAuthorize("@ss.hasPermi('baseInfo:customer:add')")
    @Log(title = "顾客信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Customer customer)
    {
        customer.setCreateBy(getUsername());
        return toAjax(customerService.insertCustomer(customer));
    }

    /**
     * 修改顾客信息
     */
    @PreAuthorize("@ss.hasPermi('baseInfo:customer:edit')")
    @Log(title = "顾客信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Customer customer)
    {
        customer.setUpdateBy(getUsername());
        return toAjax(customerService.updateCustomer(customer));
    }

    /**
     * 删除顾客信息
     */
    @PreAuthorize("@ss.hasPermi('baseInfo:customer:remove')")
    @Log(title = "顾客信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{customerIds}")
    public AjaxResult remove(@PathVariable Long[] customerIds)
    {
        return toAjax(customerService.deleteCustomerByIds(customerIds, getUsername()));
    }
}
